package com.pro.controller;

import com.google.gson.Gson;
import com.pro.mapper.JsTransactionStatisticsMapper;
import com.pro.pojo.JsCourse;
import com.pro.pojo.JsProduct;
import com.pro.pojo.JsonData;
import com.pro.service.JsTransactionStatisticsService;
import com.pro.utils.RedisCache;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName:JsTransactionStatisticsController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2021/12/7 18:40
 * @Author: XJR
 */
@RestController
@RequestMapping("/JsTransaction")
public class JsTransactionStatisticsController {
    @Autowired
    private JsTransactionStatisticsService service;

    @Autowired
    private RedisCache redisCache;

    private Gson gson = new Gson();


    //查看商品订单
    @RequestMapping("/selectGoodsStatistics")
    public JsonData selectGoodsStatistics(){
        List<JsProduct> jsProducts = service.selectGoodsStatistics();
        String selectGoodsStatistics = redisCache.getCacheObject("selectGoodsStatistics");
        List<JsProduct> list = gson.fromJson(selectGoodsStatistics, List.class);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务端错误");
    };
    //查看课程订单
    @RequestMapping("/selectCurriculumStatistics")
    public JsonData selectCurriculumStatistics(){
        List<JsCourse> jsCourses = service.selectCurriculumStatistics();
        String selectCurriculumStatistics = redisCache.getCacheObject("selectCurriculumStatistics");
        List<JsCourse>  list = gson.fromJson(selectCurriculumStatistics, List.class);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务端错误");
    };
}
